using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.DataTier.Compiled;

namespace OR.Lazarus.Library.DataTier.Compiled.Lazarus
{
	/// <summary>
	/// Defines a collection of a single type of entity (and it's descendants).
	/// </summary>
   public class CollectionDetail : EntityBase
   {
		protected System.String mName;
		protected string mAlias;
		protected string mBindingObject;
		protected string mBindingField;
		protected string mObject;
		protected string mFilename;
		protected string mDescription;

		public CollectionDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// Defines the XML Element name for the collection.
		/// </summary>
		public string Alias
		{
			get
			{
				return ( mAlias );
			}
			set
			{
				mAlias = value;
			}
		}

		/// <summary>
		/// Specifies the Object that contains the collection references.  This will default to the Object, but should be specified if an Intersection is being used.
		/// </summary>
		public string BindingObject
		{
			get
			{
				return ( mBindingObject );
			}
			set
			{
				mBindingObject = value;
			}
		}

		/// <summary>
		/// Specifies the FK value in the Binding Object that relates back to the current Collection.
		/// </summary>
		public string BindingField
		{
			get
			{
				return ( mBindingField );
			}
			set
			{
				mBindingField = value;
			}
		}

		/// <summary>
		/// Specifies what entity the collection is comprised of.
		/// </summary>
		public string Object
		{
			get
			{
				return ( mObject );
			}
			set
			{
				mObject = value;
			}
		}

		/// <summary>
		/// Specifies the base filename for the Collection.
		/// </summary>
		public string Filename
		{
			get
			{
				return ( mFilename );
			}
			set
			{
				mFilename = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mAlias = DataUtility.GetString( pSource, "alias" );
			mBindingObject = DataUtility.GetString( pSource, "binding-object" );
			mBindingField = DataUtility.GetString( pSource, "binding-field" );
			mObject = DataUtility.GetString( pSource, "object" );
			mFilename = DataUtility.GetString( pSource, "filename" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lzc:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lzc", "collection", "http://schemas.icitadel.com/Lazarus/Compiled.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mAlias ) )
			{
				vNewElement.SetAttribute( "alias", mAlias );
			}
					
			if ( !String.IsNullOrEmpty( mBindingObject ) )
			{
				vNewElement.SetAttribute( "binding-object", mBindingObject );
			}
					
			if ( !String.IsNullOrEmpty( mBindingField ) )
			{
				vNewElement.SetAttribute( "binding-field", mBindingField );
			}
					
			if ( !String.IsNullOrEmpty( mObject ) )
			{
				vNewElement.SetAttribute( "object", mObject );
			}
					
			if ( !String.IsNullOrEmpty( mFilename ) )
			{
				vNewElement.SetAttribute( "filename", mFilename );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lzc", "description", "http://schemas.icitadel.com/Lazarus/Compiled.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.CollectionDetail v_oReturn = new Derived.CollectionDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Alias = mAlias;
			v_oReturn.BindingObject = mBindingObject;
			v_oReturn.BindingField = mBindingField;
			v_oReturn.Object = mObject;
			v_oReturn.Filename = mFilename;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.CollectionDetail CloneTyped()
		{
			return ( ( Derived.CollectionDetail )this.Clone() );
		}
   }
}
   